<?php

use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class CourseRatingSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'CourseSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $courses = $this->fetchAll('SELECT * FROM kg_course');

        $rows = [];
        foreach ($courses as $course) {
            $rows[] = [
                'course_id' => $course['id'],
                'rating' => $faker->randomFloat(2, 4, 5),
                'rating1' => $faker->randomFloat(2, 4, 5),
                'rating2' => $faker->randomFloat(2, 4, 5),
                'rating3' => $faker->randomFloat(2, 4, 5),
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_course_rating')->insert($rows)->saveData();
    }

}
